﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;

namespace TreeControl
{
    public class TreeItem
    {
        private List<TreeItem> myItems = new List<TreeItem>();
        private static Brush myTextBrush = new SolidBrush(Color.FromArgb(172, 172, 242));

        public string Name { get; set; }

        public string Id { get; set; }

        public TreeItem(string id, string name, int width, int locationY)
        {
            Id = id;
            Name = name;

            ReadSettings();

            int height = Configurations.ItemHeight;
            this.BoundingRectangle = new Rectangle(0, locationY, width, height);
        }

        private void ReadSettings()
        {

        }

        public Rectangle BoundingRectangle { get; private set; }

        public TreeItem[] Items
        {
            get
            {
                return myItems.ToArray();
            }
        }

        public TreeItem AddItem(string id, string name)
        {
            int locationY = this.BoundingRectangle.Bottom;
            TreeItem tempItem = new TreeItem(id, name, this.BoundingRectangle.Width, locationY);
            myItems.Add(tempItem);
            this.BoundingRectangle = new Rectangle(this.BoundingRectangle.Left, this.BoundingRectangle.Top, this.BoundingRectangle.Width,
                this.BoundingRectangle.Height + tempItem.BoundingRectangle.Height);
            return tempItem;
        }

        internal void Draw(Graphics graphics)
        {
            graphics.DrawString(Name, Configurations.Font, myTextBrush, (float)BoundingRectangle.Left + 2, (float)BoundingRectangle.Top + 5);
            graphics.DrawRectangle(Pens.Black, BoundingRectangle);
        }
    }
}
